import { BasicClassField } from "@@/apis/basic-data/types"
import { PageRequestData, TableData } from "@@/apis/common"

export interface BasicDataInfo {
  // 主键
  id?: string
  // 编码
  code: string
  // 名称
  name: string
  // 描述
  description: string
  // 标签名称
  tag: string[] | string
  // 父类id
  parentId: string
  // 父类
  parentComponent?: BasicDataInfo
}

export interface MethodField {
  id?: string
  // static virtual normal
  type?: "static" | "virtual" | "normal"
  // 返回值类型
  returnType?: string;
  // 函数名
  name?: string;
  // 所属组件模型
  componentId?: string;

  isAdd?: boolean
}

export interface CmpTableData extends BasicDataInfo, TableData {
  id: string
}

export interface SaveRequestData {
  component: BasicDataInfo
  insertFields?: BasicClassField[]
  updateFields?: BasicClassField[]
  removeFields?: BasicClassField[]
  insertStaticFields?: BasicClassField[]
  updateStaticFields?: BasicClassField[]
  removeStaticFields?: BasicClassField[]
  insertMethods?: MethodField[]
  updateMethods?: MethodField[]
  removeMethods?: MethodField[]
}


export interface ParentComponent {
  code: string;
  name: string;
}
// 组件模型参数
export interface ModelData {
  id: string
  code: string
  name: string
  tag: string
  description: string
  createTime: string
  updateTime: string
  parentComponent?: {
    id: string
    name: string
  }
}
// 组件模型详情参数
export interface ModelDetailData {
  id?: string
  staticFlag: number
  name: string
  code: string
  description?: string
  type: string
  value?: string
  recordType: string
  typeCode: string
  typeId: number | string
  parentId?: string
  tag?: string
  separator: string
}
// 搜索参数
export interface ModelSearchData extends Partial<ModelData>, PageRequestData {
  tags: string[]
}
// 组件模型列表返回
export interface ModelResponse {
  data: {
    rows: ModelData[]
    total: number
  }
}
// 组件模型详情
export interface ModelDetail {
  data: {
    component: ModelData
    fields: ModelDetailData[]
    methods: []
  }
}
// 保存组件模型
export interface SaveModelData {
  component: ModelData
  insertFields: ModelDetailData[]
  insertStaticFields: ModelDetailData[]
  insertMethods: ModelDetailData[]
  updateFields: ModelDetailData[]
  updateStaticFields: ModelDetailData[]
  updateMethods: ModelDetailData[]
  removeFields: ModelDetailData[]
  removeStaticFields: ModelDetailData[]
  removeMethods: ModelDetailData[]
}

export interface BasicViewInfo {
  component: BasicDataInfo
  fields: BasicClassField[]
  methods: [],
  files: []
}

export type ModelViewResData = ApiResponseData<BasicViewInfo>